package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.server.DishServer;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Autowired
    private DishServer dishServer;


    /**
     * 分页查询
     */
    @GetMapping("/page")
    public Result<PageResult> pageEmployee(DishPageQueryDTO queryDTO) {
        PageResult pageResult = dishServer.pageEmployee(queryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id查菜品
     */
    @GetMapping("/{id}")
    public Result<DishVO> getById(@PathVariable Long id) {
        DishVO dishVO = dishServer.getById(id);
        return Result.success(dishVO);
    }

    /**
     * 新增菜品
     */
    @PostMapping()
    public Result addDish(@RequestBody DishDTO requestDTO) {
        dishServer.addDish(requestDTO);
        return Result.success();
    }

    /**
     * 根据分类id查取菜品列表
     */
    @GetMapping("/list")
    public Result<List<DishVO>> listByCategoryId(Integer categoryId) {
        List<DishVO> dishList = dishServer.listByCategoryId(categoryId);
        return Result.success(dishList);
    }


    /**
     * 修改菜品信息
     */
    @PutMapping()
    public Result update(@RequestBody DishDTO dishDTO) {
        dishServer.update(dishDTO);
        return Result.success();
    }


    /**
     * 修改dish状态
     */
    @PostMapping("/status/{status}")
    public Result status(@PathVariable Integer status, Long id) {
        Dish dish = new Dish();
        dish.setStatus(status);
        dish.setId(id);
        dishServer.status(dish);
        return Result.success();
    }

    /**
     * 批量删除
     *
     * @return
     */
    @DeleteMapping()
    public Result<Object> deleteByIds(Long[] ids) {
        dishServer.deleteByIds(ids);
        return Result.success();
    }


}
